package com.wei.czz.common.enums.blog.audit;

import com.wei.czz.common.dto.common.NameValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2024-11-29 14:51:19
 * className: AuditTypeEnum
 * version: 1.0
 * description:
 */
@Getter
@AllArgsConstructor
public enum AuditTypeEnum {

    NEW_BLOG(0, "新博客审核"),

    UPDATE_BLOG(1, "博客修改审核"),

    APPEAL_BLOG(2, "博客申诉审核"),

    ;

    /**
     * 值
     */
    private final Integer value;

    /**
     * 名称
     */
    private final String name;

    /**
     * 获取枚举名称
     * @param value 枚举值
     * @return 名称
     */
    public static String getName(Integer value) {
        for (AuditTypeEnum auditTypeEnum : values()) {
            if (auditTypeEnum.value.equals(value)) {
                return auditTypeEnum.name;
            }
        }
        return "";
    }

    /**
     * 获取枚举列表
     * @return 枚举列表
     */
    public static List<NameValue<Integer>> getList() {
        return Stream.of(values())
                .map(auditTypeEnum -> new NameValue<>(auditTypeEnum.getName(), auditTypeEnum.getValue()))
                .collect(Collectors.toList());
    }

    /**
     * 获取枚举对象
     * @param name 名称
     * @return 枚举对象
     */
    public static AuditTypeEnum find(String name) {
        for (AuditTypeEnum auditTypeEnum : values()) {
            if (auditTypeEnum.name.equals(name)) {
                return auditTypeEnum;
            }
        }
        return null;
    }
}
